import { useState, useCallback, useEffect } from "react";

export const useIphoneX = () => {
  const [isIphonex, setIsIphonex] = useState(false);

  const isIOS = useCallback(() => {
    return navigator.userAgent.match(/(iPhone|iPod|iPad)/i);
  }, []);

  const isIphoneX = useCallback(() => {
    try {
      if (isIOS()) {
        if (window.screen.height >= 812) {
          return true;
        }
      }
    } catch (error) {
      console.log(error);
    }
    return false;
  }, []);

  useEffect(() => {
    setIsIphonex(isIphoneX());
  }, []);

  return [isIphonex];
};
